package com.cdu.xinmiao.activity;

import static com.xuexiang.xui.utils.XToastUtils.toast;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.cdu.xinmiao.R;
import com.cdu.xinmiao.adapter.BannerAdapter;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.banner.recycler.BannerLayout;

import java.util.ArrayList;
import java.util.List;

public class ShowActivity extends AppCompatActivity {
    private TitleBar titleBar;
    private BannerLayout bannerLayout;
    private BannerAdapter mAdapter;
    private List<Integer> mImageList;
    private LinearLayout expandableLayout;
    private Button toggleButton;
    private Button btn_signup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.showactivity_activity);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.showActivity), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        getId();

        loadData();

        loadImageData();

        initAdapter();

        bindClick();
    }

    private void loadData() {
    }

    private void loadImageData() {
        // 准备轮播图数据
        mImageList = new ArrayList<>();
        mImageList.add(R.drawable.img1);
        mImageList.add(R.drawable.img2);
        mImageList.add(R.drawable.img3);
    }

    private void initAdapter() {
        mAdapter = new BannerAdapter(mImageList);
        bannerLayout.setAdapter(mAdapter);
    }

    private void bindClick() {
        titleBar.setLeftClickListener(v -> finish());
        bannerLayout = findViewById(R.id.banner_layout);
        toggleButton.setOnClickListener(v -> toggleLayout());
        btn_signup.setOnClickListener(v -> Toast.makeText(this, "报名成功!", Toast.LENGTH_SHORT).show());
    }

    private void getId() {
        titleBar = findViewById(R.id.titleBar_back);
        expandableLayout = findViewById(R.id.expandable_layout);
        bannerLayout = findViewById(R.id.banner_layout);
        toggleButton = findViewById(R.id.toggle_button);
        expandableLayout.setVisibility(View.GONE);
        btn_signup = findViewById(R.id.btn_signup);
    }

    private void toggleLayout() {
        if (expandableLayout.getVisibility() == View.VISIBLE) {
            expandableLayout.setVisibility(View.GONE);
            toggleButton.setText("展开");
        } else {
            // 如果展开布局不可见，则显示它
            expandableLayout.setVisibility(View.VISIBLE);
            toggleButton.setText("收起");
        }
    }
}
